<!--
 * @Author: Charlie/彭旺
 * @email: 413157399@qq.com
 * @Date: 2022-06-17 15:40:28
-->
<template>
  <div class="app-container">
    <!--表单组件-->
    <eForm ref="form" :is-add="isAdd" />
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" size="small" style="width: 100%">
      <el-table-column prop="id" label="id" />
      <el-table-column prop="name" label="等级名称" />
      <el-table-column prop="grade" label="会员等级" />
      <el-table-column prop="number" label="数量" />
      <el-table-column prop="unit" label="单位" />
      <el-table-column label="操作" width="150px" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-edit"
            @click="editClick(scope.row)"
          />
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <el-pagination
      :total="total"
      style="margin-top: 8px"
      layout="total, prev, pager, next, sizes"
      :page-sizes="[10, 20, 50, 100]"
      @size-change="sizeChange"
      @current-change="pageChange"
    />
  </div>
</template>

<script>
import { get } from "@/api/yxSystemUserLevel";
// import initData from '@/mixins/crud'
import eForm from "./form";
export default {
  components: { eForm },
  // mixins: [initData],
  data() {
    return {
      delLoading: false,
      pagePara: {
        pageNum: 1,
        pageSize: 10,
      },
      total: 0,
      data: [],
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    getList() {
      this.delLoading = true;
      get(this.pagePara)
        .then((res) => {
          this.delLoading = false;
          if (res.status == "1") {
            this.data = res.data.records;
            this.total = res.data.total;
          }
        })
        .catch((err) => {
          this.delLoading = false;
          console.log(err.response.data.message);
        });
    },
    editClick(data) {
      this.isAdd = false;
      const _this = this.$refs.form;
      _this.form = {
        id: data.id,
        name: data.name,
        grade: data.grade,
        number: data.number,
        unit: data.unit,
      };
      _this.dialog = true;
    },

    sizeChange(val) {
      console.log(val);
      this.page.currentPage = 1;
      this.page.pageSize = val;
      this.getPage(this.page);
    },
  },
};
</script>